package com.tjec.project.system.controller;

import java.util.List;

import com.tjec.project.projectLeaderWorkbeanch.domain.BmsMdExpertType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.project.system.domain.BmsMdArea;
import com.tjec.project.system.service.IBmsMdAreaService;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 省市区Controller
 * 
 * @author cjj
 * @date 2020-04-28
 */
@Api(value = "省市区" , tags = {"基础数据-省市区接口"})
@RestController
@RequestMapping("/system/area")
public class BmsMdAreaController extends BaseController
{
    @Autowired
    private IBmsMdAreaService bmsMdAreaService;

    /**
     * 查询省市区列表
     */
    @GetMapping("/list")
    @ApiOperation("查询省市区列表")
    public TableDataInfo list(BmsMdArea bmsMdArea)
    {
        startPage();
        if(null == bmsMdArea.getType()||("").equals(bmsMdArea.getType())){
            bmsMdArea.setType(1L);
        }
        List<BmsMdArea> list = bmsMdAreaService.selectBmsMdAreaList(bmsMdArea);
        return getDataTable(list);
    }

    /**
     * 省市区树（三层结构）
     */
    @GetMapping("/tree")
    @ApiOperation("省市区列表树")
    public AjaxResult tree(BmsMdArea bmsMdArea)
    {
        List<BmsMdArea> list = bmsMdAreaService.selectBmsMdAreaList(bmsMdArea);
        return AjaxResult.success(bmsMdAreaService.buildBmsMdAreaTreeSelect(list));
    }

    /**
     * 省市区树（二层结构）
     */
    @GetMapping("/treeTwo")
    @ApiOperation("省市区列表树")
    public AjaxResult treeTwo(BmsMdArea bmsMdArea)
    {
        List<BmsMdArea> list = bmsMdAreaService.selectBmsMdAreaListTwo(bmsMdArea);
        return AjaxResult.success(bmsMdAreaService.buildBmsMdAreaTreeSelect(list));
    }

    /**
     * 导出省市区列表
     */
    @Log(title = "省市区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsMdArea bmsMdArea)
    {
        List<BmsMdArea> list = bmsMdAreaService.selectBmsMdAreaList(bmsMdArea);
        ExcelUtil<BmsMdArea> util = new ExcelUtil<BmsMdArea>(BmsMdArea.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取省市区详细信息
     */
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(bmsMdAreaService.selectBmsMdAreaByGuid(guid));
    }

    /**
     * 新增省市区
     */
    @Log(title = "省市区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsMdArea bmsMdArea)
    {
        return toAjax(bmsMdAreaService.insertBmsMdArea(bmsMdArea));
    }

    /**
     * 修改省市区
     */
    @Log(title = "省市区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsMdArea bmsMdArea)
    {
        return toAjax(bmsMdAreaService.updateBmsMdArea(bmsMdArea));
    }

    /**
     * 删除省市区
     */
    @Log(title = "省市区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(bmsMdAreaService.deleteBmsMdAreaByGuids(guids));
    }
}
